//
//  AppStorageDemo.swift
//  SwiftUIDemo
//
//  Created by Tilt Wang on 2025/7/6.
//

import SwiftUI

struct AppStorageDemo: View {
    
//    @State var currentUserName: String?
    
    @AppStorage("name") var currentUserName: String?
    
    var body: some View {
        VStack(spacing: 20) {
            Text(currentUserName ?? "Add Name Here")
            
            Button("Save") {
                let name = "Zhang San"
                currentUserName = name
//                UserDefaults.standard.set(name, forKey: "name")
             }
        }
//        .onAppear {
//            currentUserName = UserDefaults.standard.string(forKey: "name")
//        }
    }
}

#Preview {
    AppStorageDemo()
}
